package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.Dept;
import com.hu.zhcc.shiro.entity.dto.RoleDTO;
import com.hu.zhcc.shiro.entity.vo.RoleDetailVO;
import com.hu.zhcc.shiro.service.DeptService;
import com.hu.zhcc.shiro.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("")
    public PageInfo<Dept> homeDept(int pageNum , int pageSize){
        PageInfo<Dept> deptPageInfo = deptService.listAll(pageNum, pageSize);
        return deptPageInfo;
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> removeDept(@PathVariable("id") int id) {
        return deptService.removeDept(id) > 0 ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Integer> updateDept(@PathVariable("id") int id, @RequestBody Dept dept) {
        int rows = deptService.updateDept(dept);
        return rows == 0 ? ResponseEntity.notFound().build() :
                ResponseEntity.status(HttpStatus.CREATED).body(rows);
    }
}
